<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>门店商品信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var subFlag = true;
		
		$(document).ready(function() {
			if("${resultCode}" != ""){
				showTip("${resultMessage}", "", 3000,0);
			}
		});
		
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		//提交
		function examine(obj,goodId){
			if(!subFlag){
				loading('正在提交，请稍等...');
				return;
			}
			obj.href = "${ctx}/sys/goodsstoremanger/examine?id="+goodId+"&examineStatus=2";
			if($("#queryPartsCode").val() != ""){
				obj.href += "&queryPartsCode="+$("#queryPartsCode").val();
			}
			if($("#queryMaterielCode").val() != ""){
				obj.href += "&queryMaterielCode="+$("#queryMaterielCode").val();
			}
			if($("#queryCnName").val() != ""){
				obj.href += "&queryCnName="+$("#queryCnName").val();
			}
			if($("#queryVenderName").val() != ""){
				obj.href += "&queryVenderName="+$("#queryVenderName").val();
			}
			if($("#queryExamineStatus").val() != ""){
				obj.href += "&queryExamineStatus="+$("#queryExamineStatus").val();
			}
			if($("#querySource").val() != ""){
				obj.href += "&querySource="+$("#querySource").val();
			}
			if($("#queryStoreCode").val() != ""){
				obj.href += "&queryStoreCode="+$("#queryStoreCode").val();
			}
			subFlag = false;
		}
		
		function batchExamine(){
			if(!subFlag){
				loading('正在提交，请稍等...');
				return;
			}
			if($("input[name=arrayId]:checked").length == 0){
				showTip("请先选择商品信息", "", 3000,0);
				return;
			}
			if(confirm('确认要提交该门店商品吗？')){
				$("#searchForm").attr("action","${ctx}/sys/goodsstoremanger/batchExamine");
				$("#searchForm").submit();
				subFlag = false;
			}
		}
		
		//删除
		function del(obj,goodId){
			if(!subFlag){
				loading('正在提交，请稍等...');
				return;
			}
			if(confirm('确认要删除该门店商品吗？')){
				obj.href = "${ctx}/sys/goodsstoremanger/delete?id="+goodId;
				if($("#queryPartsCode").val() != ""){
					obj.href += "&queryPartsCode="+$("#queryPartsCode").val();
				}
				if($("#queryMaterielCode").val() != ""){
					obj.href += "&queryMaterielCode="+$("#queryMaterielCode").val();
				}
				if($("#queryCnName").val() != ""){
					obj.href += "&queryCnName="+$("#queryCnName").val();
				}
				if($("#queryVenderName").val() != ""){
					obj.href += "&queryVenderName="+$("#queryVenderName").val();
				}
				if($("#queryExamineStatus").val() != ""){
					obj.href += "&queryExamineStatus="+$("#queryExamineStatus").val();
				}
				if($("#querySource").val() != ""){
					obj.href += "&querySource="+$("#querySource").val();
				}
				if($("#queryStoreCode").val() != ""){
					obj.href += "&queryStoreCode="+$("#queryStoreCode").val();
				}
			}else{
				return false;
			}
			subFlag = false;
		}
		
		function batchDel(){
			if(!subFlag){
				loading('正在提交，请稍等...');
				return;
			}
			if($("input[name=arrayId]:checked").length == 0){
				showTip("请先选择商品信息", "", 3000,0);
				return;
			}
			if(confirm('确认要删除该门店商品吗？')){
				$("#searchForm").attr("action","${ctx}/sys/goodsstoremanger/batchDelete");
				$("#searchForm").submit();
				subFlag = false;
			}
		}
		
		function exp(){
			$("#searchForm").attr("action","${ctx}/sys/goodsstoremanger/export");
			$("#searchForm").submit();
			$("#searchForm").attr("action","${ctx}/sys/goodsstoremanger/");
			alert('开始导出，请稍等...');
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/goodsstoremanger/">门店商品列表</a></li>
		<shiro:hasPermission name="sys:goodsstoremanger:edit"><li><a href="${ctx}/sys/goodsstoremanger/form">门店商品添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="goods" action="${ctx}/sys/goodsstoremanger/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>配件编号：</label>
				<form:input path="queryPartsCode" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>物料编号：</label>
				<form:input path="queryMaterielCode" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>商品名称：</label>
				<form:input path="queryCnName" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>制造商品牌：</label>
				<form:select path="queryVenderId" style="width:100px;">
					<option  value="">所有</option>
					<form:options items="${venderList}" itemLabel="name" itemValue="id" />
				</form:select>
			</li>
			<li class="clearfix"></li>
		</ul>
		<ul class="ul-form">
			<li><label>状态：</label>
				<form:select path="queryExamineStatus" class="input-medium">
					<option value="">所有</option>
					<form:options items="${goodsExamineStatusList}" itemValue="value" itemLabel="label"/>
				</form:select>
			</li>
			<li><label>商品来源：</label>
				<form:select path="querySource" class="input-medium">
					<option value="">所有</option>
					<form:options items="${goodsourceList}" itemValue="value" itemLabel="label"/>
				</form:select>
			</li>
			<li><label>所属门店：</label>
				<form:select path="queryStoreCode" class="input-medium">
					<option value="">所有</option>
					<form:options items="${storeList}" itemValue="code" itemLabel="cnName"/>
				</form:select>
			</li>
			<li class="btns">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnSubmit" class="btn btn-primary" type="button" onclick="batchDel()" value="删除"/>
				<input id="btnSubmit" class="btn btn-primary" type="button" onclick="batchExamine()" value="提交"/>
				<input id="btnSubmit" class="btn btn-primary" type="button" onclick="exp()" value="导出"/>
			</li>
			<li class="clearfix"></li>
		</ul>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th><input type="checkbox" name="allCheck" onclick="jp_allCheck(this,'arrayId')"/>序号</th>
				<th>物料编号</th>
				<th>配件编号</th>
				<th>商品编号</th>
				<th>商品来源</th>
				<th>商品名称</th>
				<th>制造商品牌</th>
				<th>售价</th>
				<th>会员价</th>
				<th>所属门店</th>
				<th>最近修改时间</th>
				<th>审核状态</th>
				<shiro:hasPermission name="sys:goodsstoremanger:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="goods" varStatus="s">
			<tr>
				<td>
					<input type="checkbox" name="arrayId" value="${goods.id}" onclick="jp_oneCheck(this,'allCheck')"/>${s.index+1}
				</td>
				<td>
					${goods.materielCode}
				</td>
				<td>
					${goods.partsCode}
				</td>
				<td>
					<%-- <a target="_black" href="${ctxWeb}/goodsDetail/list?goodsCode=${goods.code}&storeCode=${goods.storeCode}">
					${goods.code}
					</a> --%>
					
					${goods.code}
				</td>
				<td>
					<c:forEach items="${goodsourceList}" var="bean">
						<c:if test="${bean.value == goods.source}">
							${bean.label}
						</c:if>
					</c:forEach>
				</td>
				<td>
					<a href="${ctx}/sys/goodsplatformmanger/goodsDetail?goodsCode=${goods.code}&tagUrl=${ctx}/sys/goodsstoremanger/list&tagName=门店商品列表">${goods.cnName}</a>
					<!-- <a href="${ctx}/sys/goodsstoremanger/view?id=${goods.id}">${goods.cnName}</a>  -->
				</td>
				<td>
					${goods.venderName}
				</td>
				<td>
					${goods.price}
				</td>
				<td>
					${goods.memberPrice}
				</td>
				<td>
					${goods.storeCnName}
				</td>
				<td>
					<c:if test="${goods.source == 3}">
						<fmt:formatDate value="${goods.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
					</c:if>
				</td>
				<td>
					<c:forEach items="${goodsExamineStatusList}" var="bean">
						<c:if test="${bean.value == goods.examineStatus}">
							${bean.label}
						</c:if>
					</c:forEach>
					<c:if test="${goods.examineStatus == 4}">
						<br/>
						<font color="red">
						失败原因是:
							${goods.examineInfo}
						</font>
					</c:if>
				</td>
				<shiro:hasPermission name="sys:goodsstoremanger:edit">
				<td>
					<c:if test="${goods.source == 3}">
						<c:choose>
							<c:when test="${goods.examineStatus == 1 || goods.examineStatus == 4}">
								<a href="${ctx}/sys/goodsstoremanger/form?id=${goods.id}">编辑</a>
								<a href="#" onclick="del(this,'${goods.id}')">删除</a>
								<a href="#" onclick="examine(this,'${goods.id}')">提交</a>
							</c:when>
							<c:when test="${goods.examineStatus == 3}">
								<a href="${ctx}/sys/goodsstoremanger/form?id=${goods.id}">编辑</a>
								<a href="#" onclick="del(this,'${goods.id}')">删除</a>
							</c:when>
						</c:choose>
					</c:if>
				</td>
				</shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</form:form>
	<div class="pagination">${page}</div>
</body>
</html>